package hello

import (
	"github.com/gogf/gf/net/ghttp"
	"github.com/gogf/gf/os/glog"
)

func WebsocketHandle(r *ghttp.Request) {
	ws, err := r.WebSocket()
	if err != nil {
		glog.Error(err)
		r.Exit()
	}
	for {
		msgType, msg, err := ws.ReadMessage()

		//msgStr := "> "+string(msg)
		msgStr:=append([]byte("> "),msg...)
		if err != nil {
			return
		}
		if err = ws.WriteMessage(msgType, msgStr); err != nil {
			return
		}
	}
}
